import cn.yunhe.dao.IAdminDao;
import cn.yunhe.dao.IUserDao;
import cn.yunhe.entity.Admin;
import cn.yunhe.entity.User;
import cn.yunhe.service.IAdminService;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class AdminDeom {
SqlSession sqlSession = null;
IAdminDao iAdminDao = null;
@Before
 public void inti(){
     sqlSession = SqlSessionFactoryUtil.getSqlSession();
     iAdminDao=sqlSession.getMapper(IAdminDao.class);
 }
 @Test
 public void demo1(){
     Admin admin = new Admin();
     admin.setAdminName("admin");
     admin.setAdminPass("admin");
    Admin admin1 = iAdminDao.Lading(admin);
     if (admin1==null){
         System.out.println("无结果");
     }else {
         System.out.println("有结果");
     }
 }
 @Test
 public  void demo2(){
   List<User> list= iAdminDao.Userlist();
     for (User u:list) {
         System.out.println(u.getUserId());
     }
 }
 @Test
 public void  demo3(){
     IAdminService iAdminService = new IAdminService();
      List<User> list= iAdminService.userlist();
     for (User u:list) {
         System.out.println(u.getUserId());
     }
 }
 @Test
 public void demo4(){
   boolean num = iAdminDao.delUser(2);
   if (num){
       System.out.println("效果实现");
   }else {
       System.out.println("失效");
   }
   sqlSession.commit();
 }
 @Test
 public  void demo5(){
    User user =iAdminDao.setFlaguser(19);
   int flag=  user.getFlag();
   int  id =  user.getUserId();
     if (flag==0){
         flag=1;
     }else if(flag==1){
         flag=0;
     }
     User u1 = new User();
     u1.setUserId(id);
     u1.setFlag(flag);
   int num =  iAdminDao.upUser(u1);
     if (num!=0){
         System.out.println("效果实现");
     }else {
         System.out.println("失效");
     }
     sqlSession.commit();
 }
 @Test
 public void demo6(){
    SqlSession session =null;
     IUserDao iUserDao = null;
     session = SqlSessionFactoryUtil.getSqlSession();
     iUserDao=session.getMapper(IUserDao.class);
    User num =iUserDao.setUserName("张浩");
      if (num!=null){
          System.out.println("结果可行");
      }else {
          System.out.println("select 的所有语句都要用对象来接受");
      }
 }
 @Test
 public void demo7(){
     SqlSession session =null;
     IUserDao iUserDao = null;
     session = SqlSessionFactoryUtil.getSqlSession();
     iUserDao=session.getMapper(IUserDao.class);
     User u = new User();
     u.setUserName("杰瑞");
     u.setUserPass("123");
     u.setAddress("上蒂亚戈的鼠洞");
     u.setTelphone("14753214789");
    int num =iUserDao.inserUser(u);
     if(num>0){
         System.out.println("成功");
     }else {
         System.out.println("不行");
     }
     session.commit();
 }
 @Test
 public void demo8(){
     SqlSession session =null;
     IUserDao iUserDao = null;
     session = SqlSessionFactoryUtil.getSqlSession();
     iUserDao=session.getMapper(IUserDao.class);
     User u  = new User("user","123");
    User user = iUserDao.userLading(u);
       if (user!=null){
           System.out.println("成立");
       }else {
           System.out.println("失败");
       }
 }
 @Test
 public void demo9(){
   int num =   iAdminDao.numuser();
     System.out.println(num);
 }
 public  void demo10(){

 }
 @After
 public void destory(){ sqlSession.close();}
}
